window.onload = function(){
    //模块一页面初始化
    getList_1('', 'GetFoodClassifyListServlet', '1', '0');
}
//导航栏切换
var oBtn = document.getElementsByClassName("leftList");
var oRightPage = document.getElementsByClassName("rightPage");

for(var i = 0; i < oBtn.length; i ++){
    oBtn[i].index = i;
    oBtn[i].onclick = function(){
        for(var k = 0; k < oRightPage.length; k ++){
            oRightPage[k].className = "rightPage";
            oBtn[k].className = "layui-btn layui-btn-fluid leftList"
        }
        oBtn[this.index].className = "layui-btn layui-btn-fluid leftList listActive";
        oRightPage[this.index].className = "rightPage active";
        var data = {keyword: ''};
        if(this.index == 0){
            getList_1(data, 'GetFoodClassifyListServlet', 1, 0);
        }else if(this.index == 1){
            getList_1(data, 'GetFoodInfoListServlet', 2, 0);
        }else if(this.index == 2){
            eChart();
        }else if(this.index == 3){
            getList_1(data, 'GetOrganizeInfoListServlet', 4, 0);
        }else if(this.index == 4){
            getList_1(data, 'GetCollectInfoListServlet', 5, 0);
        }else if(this.index == 5){
            setUser();
        }
    }
}


//页面1点击添加事件 取消
$(".addBtn_1").click(function(){
    $(".addList").css("display","block");
})
$(".Btn-back").click(function(){

    //模块一  清空表单并关闭
    var $type = document.getElementById("input-type-1");
    var $name = document.getElementById("input-name-1");
    var $exp = document.getElementById("input-exp-1");
    $type.value = '';
    $name.value = '';
    $exp.value = '';
    $(".addList").css("display","none");
})

//页面2点击添加事件 取消
$(".addBtn_2").click(function(){
    $(".addList_2").css("display","block");
})
$(".Btn-back_2").click(function(){
    $(".addList_2").css("display","none");
     //模块一  清空表单
     btnInit();
})

//页面4点击添加事件 取消
$(".addBtn_4").click(function(){
    $(".addList_4").css("display","block");
})
$(".Btn-back_4").click(function(){
    //模块一  清空表单并关闭
    var $type = document.getElementById("input-type-4");
    var $name = document.getElementById("input-name-4");
    var $exp = document.getElementById("input-exp-4");
    $type.value = '';
    $name.value = '';
    $exp.value = '';
    $(".addList_4").css("display","none");
})
//页面5点击添加事件 取消
$(".addBtn_5").click(function(){
    $(".addList_5").css("display","block");
})
$(".Btn-back_5").click(function(){
    document.getElementById("input-list-id").value = '';
    document.getElementById("input-list-name").value = '';
    document.getElementById("input-list-number_1").value = '';
    document.getElementById("input-list-number_2").value = '';
    document.getElementById("input-list-number_3").value = '';
    document.getElementById("input-list-number_4").value = '';
    document.getElementById("input-list-number_5").value = '';
    $(".addList_5").css("display","none");
})

//模块一搜索
$("#select_1").click(function(){
    var val = $("#topIup_1").val();
    if(val == ''){
        message("查询内容不能为空!", 0);
    }else{
        var data = {keyword: val}
        getList_1(data, 'GetFoodClassifyListServlet', 1, 1);
    }
})
//模块一添加
$('.addBtn_1').click(function(){
    $("#add-save").unbind('click').click(function(){
       
        var type = document.getElementById("input-type-1").value;
        var name = document.getElementById("input-name-1").value;
        var exp = document.getElementById("input-exp-1").value;
        if(type == ''||name == ''){
            message('必填项不能为空', 0);
        }else{
            var sendData = {
                type: type,
                name: name,
                exp: exp
            }
            reOnload(sendData, 'AddFoodClassifyServlet', 1);
        }
    });
});


//模块二 搜索
$("#select_2").click(function(){
    var val = $("#topIup_2").val();
    if(val == ''){
        message("查询内容不能为空!", 0);
    }else{
        var data = {keyword: val}
        getList_1(data, 'GetFoodInfoListServlet', 2, 1);
    }
})
//模块二 添加
$('.addBtn_2').click(function(){
    $(".Btn-save_2").unbind('click').click(function(){
        var oId = document.getElementById("foodId").value;
        var oName = document.getElementById("name").value;
        var oDate = document.getElementById("date").value;
        var oFoodPest = document.getElementById("foodPest").value;
        var oFoodPestInfo = document.getElementById("foodPestInfo").value;
        var oFoodVeter = document.getElementById("foodVeter").value;
        var oFoodVeterInfo = document.getElementById("foodVeterInfo").value;
        var oFoodMetal = document.getElementById("foodMetal").value;
        var oFoodMetalInfo = document.getElementById("foodMetalInfo").value;
        var oFoodToxin = document.getElementById("foodToxin").value;
        var oFoodToxinInfo = document.getElementById("foodToxinInfo").value;
        var oFoodAddi = document.getElementById("foodAddi").value;
        var oFoodAddiInfo = document.getElementById("foodAddiInfo").value;
        var oFoodWrap = document.getElementById("foodWrap").value;
        var oFoodWrapInfo = document.getElementById("foodWrapInfo").value;
        if(oId == ''||oName == ''||oDate == ''){
            message('必填项不能为空', 0);
        }else{
            var sendData = {
                id: oId,
                name: oName,
                foodDate: oDate,
                foodPest: oFoodPest,
                foodPestInfo: oFoodPestInfo,
                foodVeter: oFoodVeter,
                foodVeterInfo: oFoodVeterInfo,
                foodMetal: oFoodMetal,
                foodMetalInfo: oFoodMetalInfo,
                foodToxin: oFoodToxin,
                foodToxinInfo: oFoodToxinInfo,
                foodAddi: oFoodAddi,
                foodAddiInfo: oFoodAddiInfo,
                foodWrap: oFoodWrap,
                foodWrapInfo: oFoodWrapInfo
            }
            reOnload(sendData, 'AddFoodInfoServlet', 2);
            btnInit();
        }
    });
});

//模块四 搜索
$("#select_4").click(function(){
    var val = $("#topIup_4").val();
    if(val == ''){
        message("查询内容不能为空!", 0);
    }else{
        var data = {keyword: val}
        getList_1(data, 'GetOrganizeInfoListServlet', 4, 1);
    }
})
//模块四 添加
$('.addBtn_4').click(function(){
    $(".Btn-save_4").unbind('click').click(function(){
       
        var type = document.getElementById("input-type-4").value;
        var name = document.getElementById("input-name-4").value;
        var exp = document.getElementById("input-exp-4").value;
        if(type == ''||name == ''){
            message('必填项不能为空', 0);
        }else{
            var sendData = {
                id: type,
                name: name,
                content: exp
            }
            reOnload(sendData, 'AddOrganizeInfoServlet', 4);
        }
    });
});

//模块五 搜索
$("#select_5").click(function(){
    var val = $("#topIup_5").val();
    if(val == ''){
        message("查询内容不能为空!", 0);
    }else{
        var data = {keyword: val}
        getList_1(data, 'GetCollectInfoListServlet', 5, 1);
    }
})
//模块五 添加
$('.addBtn_5').click(function(){
    $(".Btn-save_5").unbind('click').click(function(){
       
        var id = document.getElementById("input-list-id").value;
        var name = document.getElementById("input-list-name").value;
        var collect1 = document.getElementById("input-list-number_1").value;
        var collect2 = document.getElementById("input-list-number_2").value;
        var collect3 = document.getElementById("input-list-number_3").value;
        var collect4 = document.getElementById("input-list-number_4").value;
        var collect5 = document.getElementById("input-list-number_5").value;
        if(id == ''||name == ''){
            message('必填项不能为空', 0);
        }else{
            var sendData = {
                id: id,
                name: name,
                collect1: collect1,
                collect2: collect2,
                collect3: collect3,
                collect4: collect4,
                collect5: collect5
            }
            reOnload(sendData, 'AddCollectInfoServlet', 5);
            btnInit();
        }
    });
});


//模板一 二 四 五  修改button   oDiv 对应板块  data 数据列表 flag对应的板块号
function getBtn_1(oDiv, data, flag){
    var oBtn = oDiv.getElementsByClassName("Btn-reWrite");
    for(var i = 0; i < oBtn.length; i ++){
        oBtn[i].index = i;
        oBtn[i].onclick = function(){
            //板块一表单修改
            if(flag == 1){
                $(".addList").css("display","block");
                var $type = document.getElementById("input-type-1");
                var $name = document.getElementById("input-name-1");
                var $exp = document.getElementById("input-exp-1");
                var val = this.getAttribute("data-id");
                for(var k = 0; k < data.getFoodList.length; k ++){
                    if(data.getFoodList[k].type == val){
                        $type.value = data.getFoodList[k].type;
                        $name.value = data.getFoodList[k].kind;
                        $exp.value = data.getFoodList[k].exp;
                    }
                }
                $(".Btn-save").unbind('click').click(function(){
                    var sendData = {
                        oldType: val,
                        type: $type.value,
                        name: $name.value,
                        exp: $exp.value
                    };
                    if(sendData.type == ''||sendData.name == ''){
                        message('必填项不能为空', 0);
                    }else{
                        reOnload(sendData, 'ChangeFoodClassifyServlet', 1);  //1  修改入口
                        
                    }
                });
            }else if(flag == 2){
                //版块二  修改
                $(".addList_2").css("display","block");
                var oVal = this.getAttribute("data-id");
                var oId = document.getElementById("foodId");
                var oName = document.getElementById("name");
                var oDate = document.getElementById("date");
                var oFoodPest = document.getElementById("foodPest");
                var oFoodPestInfo = document.getElementById("foodPestInfo");
                var oFoodVeter = document.getElementById("foodVeter");
                var oFoodVeterInfo = document.getElementById("foodVeterInfo");
                var oFoodMetal = document.getElementById("foodMetal");
                var oFoodMetalInfo = document.getElementById("foodMetalInfo");
                var oFoodToxin = document.getElementById("foodToxin");
                var oFoodToxinInfo = document.getElementById("foodToxinInfo");
                var oFoodAddi = document.getElementById("foodAddi");
                var oFoodAddiInfo = document.getElementById("foodAddiInfo");
                var oFoodWrap = document.getElementById("foodWrap");
                var oFoodWrapInfo = document.getElementById("foodWrapInfo");
                for(var k = 0; k < data.getFoodInfoList.length; k ++){
                    if(data.getFoodInfoList[k].id == oVal){
                        oId.value = data.getFoodInfoList[k].id;
                        oName.value = data.getFoodInfoList[k].name;
                        oDate.value = data.getFoodInfoList[k].date;
                        oFoodPest.value = data.getFoodInfoList[k].foodPest;
                        oFoodPestInfo.value = data.getFoodInfoList[k].foodPestInfo;
                        oFoodVeter.value = data.getFoodInfoList[k].foodVeter;
                        oFoodVeterInfo.value = data.getFoodInfoList[k].foodVeterInfo;
                        oFoodMetal.value = data.getFoodInfoList[k].foodMetal;
                        oFoodMetalInfo.value = data.getFoodInfoList[k].foodMetalInfo;
                        oFoodToxin.value = data.getFoodInfoList[k].foodToxin;
                        oFoodToxinInfo.value = data.getFoodInfoList[k].foodToxinInfo;
                        oFoodAddi.value = data.getFoodInfoList[k].foodAddi;
                        oFoodAddiInfo.value = data.getFoodInfoList[k].foodAddiInfo;
                        oFoodWrap.value = data.getFoodInfoList[k].foodWrap;
                        oFoodWrapInfo.value = data.getFoodInfoList[k].foodWrapInfo;
                    }
                }

                $(".Btn-save_2").unbind('click').click(function(){
                    var sendData = {
                        oldID: oVal,
                        id: oId.value,
                        name: oName.value,
                        foodDate: oDate.value,
                        foodPest: oFoodPest.value,
                        foodPestInfo: oFoodPestInfo.value,
                        foodVeter: oFoodVeter.value,
                        foodVeterInfo: oFoodVeterInfo.value,
                        foodMetal: oFoodMetal.value,
                        foodMetalInfo: oFoodMetalInfo.value,
                        foodToxin: oFoodToxin.value,
                        foodToxinInfo: oFoodToxinInfo.value,
                        foodAddi: oFoodAddi.value,
                        foodAddiInfo: oFoodAddiInfo.value,
                        foodWrap: oFoodWrap.value,
                        foodWrapInfo: oFoodWrapInfo.value
                    };
                    if(sendData.id == ''||sendData.name == ''||sendData.foodDate == ''){
                        message('必填项不能为空', 0);
                    }else{
                        reOnload(sendData, 'ChangeFoodInfoServlet', 2);  //1  修改入口
                        btnInit();
                    }
                });
            }else if(flag == 4){
                $(".addList_4").css("display","block");
                var $type = document.getElementById("input-type-4");
                var $name = document.getElementById("input-name-4");
                var $exp = document.getElementById("input-exp-4");
                var val = this.getAttribute("data-id");
                for(var k = 0; k < data.getOrganizeInfoList.length; k ++){
                    if(data.getOrganizeInfoList[k].id == val){
                        $type.value = data.getOrganizeInfoList[k].id;
                        $name.value = data.getOrganizeInfoList[k].name;
                        $exp.value = data.getOrganizeInfoList[k].infoContent;
                    }
                }
                $(".Btn-save_4").unbind('click').click(function(){
                    var sendData = {
                        oldID: val,
                        id: $type.value,
                        name: $name.value,
                        content: $exp.value
                    };
                    if(sendData.type == ''||sendData.name == ''){
                        message('必填项不能为空', 0);
                    }else{
                        reOnload(sendData, 'ChangeOrganizeInfoServlet', 4);  //1  修改入口
                    }
                });
            }else if(flag == 5){
                $(".addList_5").css("display","block");
                var id = document.getElementById("input-list-id");
                var name = document.getElementById("input-list-name");
                var number_1 = document.getElementById("input-list-number_1");
                var number_2 = document.getElementById("input-list-number_2");
                var number_3 = document.getElementById("input-list-number_3");
                var number_4 = document.getElementById("input-list-number_4");
                var number_5 = document.getElementById("input-list-number_5");
                var val = this.getAttribute("data-id");
                for(var k = 0; k < data.getCollectInfoList.length; k ++){
                    if(data.getCollectInfoList[k].id == val){
                        id.value = data.getCollectInfoList[k].id;
                        name.value = data.getCollectInfoList[k].name;
                        number_1.value = data.getCollectInfoList[k].collect1;
                        number_2.value = data.getCollectInfoList[k].collect2;
                        number_3.value = data.getCollectInfoList[k].collect3;
                        number_4.value = data.getCollectInfoList[k].collect4;
                        number_5.value = data.getCollectInfoList[k].collect5;
                    }
                }
                $(".Btn-save_5").unbind('click').click(function(){
                    var sendData = {
                        oldID: val,
                        id: id.value,
                        name: name.value,
                        collect1: number_1.value,
                        collect2: number_2.value,
                        collect3: number_3.value,
                        collect4: number_4.value,
                        collect5: number_5.value
                    };
                    if(sendData.id == ''||sendData.name == ''){
                        message('必填项不能为空', 0);
                    }else{
                        reOnload(sendData, 'ChangeCollectInfoServlet', 5);  //1  修改入口
                    }
                });
            }
        }
    }
}

//模板一 二 四 五  删除button
function getBtn_2(oDiv, data, flag){
    var oBtn = oDiv.getElementsByClassName("Btn-delete");
    for(var i = 0; i < oBtn.length; i ++){
        oBtn[i].index = i;
        oBtn[i].onclick = function(){
            var val = this.getAttribute("data-id");
            var r = confirm("确认删除！");
            if(r){
                if(flag == 1){
                	var data = {type: val}
                    listDelete(data, 'DeleteFoodClassifyServlet', 1);
                }else if(flag == 2){
                	var data = {id: val}
                    listDelete(data, 'DeleteFoodInfoServlet', 2);
                }else if(flag == 4){
                	var data = {id: val}
                    listDelete(data, 'DeleteOrganizeInfoServlet', 4);
                }else if(flag == 5){
                	var data = {id: val}
                    listDelete(data, 'DeleteCollectInfoServlet', 5);
                }
                
            }
        }
    }
}
//一 二 四 五  板块 请求数据方法   value 查询条件   url请求地址   page 对应模块  resMethod 响应方法
function getList_1(value, url, page, resMethod){
   $.ajax({
       type: 'post',
       url: url,
       contentType: "application/x-www-form-urlencoded",
       data: value,
       dataType: "json",
       success: function(res){
           var data = res;
           if(data.code == "1"){
               //响应成功

               //渲染板块 一
               if(page == 1){
                var oDiv = document.getElementsByClassName("dataList_1")[0];
                oDiv.innerHTML = '';
                var html = "";
                for(var i = 0; i < data.getFoodList.length; i++){
                    html += '<tr>';
                    html += '<td>'+ (i+1) +'</td>';
                    html += '<td>'+ data.getFoodList[i].type +'</td>';
                    html += '<td>'+ data.getFoodList[i].kind +'</td>';
                    html += '<td>'+ data.getFoodList[i].exp +'</td>';
                    html += '<td>';
                    html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs Btn-reWrite" data-id='+ data.getFoodList[i].type +'>修改</button>';
                    html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs Btn-delete" data-id='+ data.getFoodList[i].type +'>删除</button>';
                    html += '</td>';
                    html += '</tr>';
                }
                oDiv.innerHTML = html;
                if(resMethod == 0){
                	//响应板块  查询结果
                    getBtn_1(oDiv, data, 1);
                    //响应板块 删除结果
                    getBtn_2(oDiv, data, 1);
                }
                if(resMethod == 1){
                    message('查询成功！', 1);
                }
               }
               //渲染板块二
               else if(page == 2){
                    var oDiv = document.getElementsByClassName("dataList_2")[0];
                    oDiv.innerHTML = '';
                    var html = "";
                    for(var i = 0; i < data.getFoodInfoList.length; i ++){
                        html+= '<tr>';
                        html+= '<td>'+ (i+1) +'</td>';
                        html+= '<td>'+ data.getFoodInfoList[i].id +'</td>';
                        html+= '<td>'+ data.getFoodInfoList[i].name +'</td>';
                        html+= '<td>'+ data.getFoodInfoList[i].foodPest +'</td>';
                        html+= '<td>'+ data.getFoodInfoList[i].foodVeter +'</td>';
                        html+= '<td>'+ data.getFoodInfoList[i].foodMetal +'</td>';
                        html+= '<td>'+ data.getFoodInfoList[i].foodToxin +'</td>';
                        html+= '<td>'+ data.getFoodInfoList[i].foodAddi +'</td>';
                        html+= '<td>'+ data.getFoodInfoList[i].foodWrap +'</td>';
                        html+= '<td>';
                        html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs Btn-reWrite" data-id='+ data.getFoodInfoList[i].id +'>修改</button>';
                        html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs Btn-delete" data-id='+ data.getFoodInfoList[i].id +'>删除</button>';
                        html+= '</td>';
                        html+= '</tr>';
                    }
                    oDiv.innerHTML = html;
                    //响应板块  查询结果
                    getBtn_1(oDiv, data, 2);
                    //响应板块 删除结果
                    getBtn_2(oDiv, data, 2);
                    if(resMethod == 1){
                        message('查询成功！', 1);
                    }
               }else if(page == 4){
                var oDiv = document.getElementsByClassName("dataList_4")[0];
                oDiv.innerHTML = '';
                var html = "";
                for(var i = 0; i < data.getOrganizeInfoList.length; i++){
                    html += '<tr>';
                    html +='<td>'+ (i+1) +'</td>';
                    html +='<td>'+ data.getOrganizeInfoList[i].id +'</td>';
                    html +='<td>'+ data.getOrganizeInfoList[i].name +'</td>';
                    html +='<td>'+ data.getOrganizeInfoList[i].infoContent +'</td>';
                    html +='<td>';
                    html +='<button type="button" class="layui-btn layui-btn-primary layui-btn-xs Btn-reWrite" data-id='+ data.getOrganizeInfoList[i].id +'>修改</button>';
                    html +='<button type="button" class="layui-btn layui-btn-primary layui-btn-xs Btn-delete" data-id='+ data.getOrganizeInfoList[i].id +'>删除</button>';
                    html +='</td>';
                    html +='</tr>';
                }
                oDiv.innerHTML = html;
                //响应板块  查询结果
                getBtn_1(oDiv, data, 4);
                //响应板块 删除结果
                getBtn_2(oDiv, data, 4);
                if(resMethod == 1){
                    message('查询成功！', 1);
                }
               }else if(page == 5){
                var oDiv = document.getElementsByClassName("dataList_5")[0];
                oDiv.innerHTML = '';
                var html = "";
                for(var i = 0; i < data.getCollectInfoList.length; i++){
                    html += '<tr>';
                    html += '<td>'+ (i+1) +'</td>';
                    html += '<td>'+ data.getCollectInfoList[i].id +'</td>';
                    html += '<td>'+ data.getCollectInfoList[i].name +'</td>';
                    html += '<td>'+ data.getCollectInfoList[i].collectTotal +'</td>';
                    html += '<td>';
                    html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs Btn-reWrite" data-id='+ data.getCollectInfoList[i].id +'>修改</button>';
                    html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs Btn-delete" data-id='+ data.getCollectInfoList[i].id +'>删除</button>';
                    html += '</td>';
                    html += '</tr>';
                }
                oDiv.innerHTML = html;
                //响应板块  查询结果
                getBtn_1(oDiv, data, 5);
                //响应板块 删除结果
                getBtn_2(oDiv, data, 5);
                if(resMethod == 1){
                    message('查询成功！', 1);
                }
               }
           }else{
               //数据请求失败
               message('数据请求失败！', 0);
           }
       }
   })
}


//一 二 四 五  板块  修改方法   value 修改id  url请求地址  flag 入口Btn
function reOnload(value, url ,flag){
    if(flag == 1){
        $.post(url, value, function(res){
        var data =JSON.parse(res);
        if(data.code == 1){
            message('修改成功！', 1);
            var $type = document.getElementById("input-type-1");
            var $name = document.getElementById("input-name-1");
            var $exp = document.getElementById("input-exp-1");
            $type.value = '';
            $name.value = '';
            $exp.value = '';
            $(".addList").css("display","none");
            getList_1('', 'GetFoodClassifyListServlet', 1, 0);
        }else{
            message('服务器错误！', 0);
        }
    });
    }else if(flag == 2){
        $.post(url, value, function(res){
            var data =JSON.parse(res);
            if(data.code == 1){
                message('添加成功！', 1);
                $(".addList_2").css("display","none");
                document.getElementById("foodId").value = '';
                document.getElementById("name").value = '';
                document.getElementById("date").value = '';
                document.getElementById("foodPest").value = '';
                document.getElementById("foodPestInfo").value = '';
                document.getElementById("foodVeter").value = '';
                document.getElementById("foodVeterInfo").value = '';
                document.getElementById("foodMetal").value = '';
                document.getElementById("foodMetalInfo").value = '';
                document.getElementById("foodToxin").value = '';
                document.getElementById("foodToxinInfo").value = '';
                document.getElementById("foodAddi").value = '';
                document.getElementById("foodAddiInfo").value = '';
                document.getElementById("foodWrap").value = '';
                document.getElementById("foodWrapInfo").value = '';
                
                getList_1('', 'GetFoodInfoListServlet', 2, 0);
            }else{
                message('服务器错误！', 0);
            }
        });
    }else if(flag == 4){
        $.post(url, value, function(res){
        	var data = JSON.parse(res);
            if(data.code == 1){
                message('添加成功！', 1);
                var $type = document.getElementById("input-type-4");
                var $name = document.getElementById("input-name-4");
                var $exp = document.getElementById("input-exp-4");
                $type.value = '';
                $name.value = '';
                $exp.value = '';
                $(".addList_4").css("display","none");
                getList_1('', 'GetOrganizeInfoListServlet', 4, 0);
            }else{
                message('服务器错误！', 0);
            }
        });
    }else if(flag == 5){
        $.post(url, value, function(res){
            var data =JSON.parse(res);
            if(data.code == 1){
                message('添加成功！', 1);
                document.getElementById("input-list-id").value = '';
                document.getElementById("input-list-name").value = '';
                document.getElementById("input-list-number_1").value = '';
                document.getElementById("input-list-number_2").value = '';
                document.getElementById("input-list-number_3").value = '';
                document.getElementById("input-list-number_4").value = '';
                document.getElementById("input-list-number_5").value = '';
                $(".addList_5").css("display","none");
                getList_1('', 'GetCollectInfoListServlet', 5, 0);
            }else{
                message('服务器错误！', 0);
            }
        });
    }
}

//一 二 四 五  板块  删除方法 value 修改id  url请求地址 
function listDelete(value, url, page){
    $.post(url, value, function(res){
        var data =JSON.parse(res);
        if(data.code == 1){
            message('删除成功！', 1);
            if(page == 1){
            	getList_1('', 'GetFoodClassifyListServlet', 1, 0);
            }else if(page == 2){
            	getList_1(data, 'GetFoodInfoListServlet', 2, 0);
            }else if(page == 4){
            	getList_1(data, 'GetOrganizeInfoListServlet', 4, 0);
            }else if(page == 5){
            	getList_1(data, 'GetCollectInfoListServlet', 5, 0);
            }
        }else{
            message('服务器错误！', 0);
        }
    });
}

function message(value, flag){

    var successInfo = '<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop" style="display: inline-block"></i> ';
    var unSuccessInfo = '<i class="layui-icon layui-icon-close" style="font-size: 16px; color: #fff;"></i>  '
    var oDiv = $(".mes")[0];
    oDiv.style.opacity = 1;
    setTimeout(function(){
        oDiv.style.opacity = 0;
    }, 3000);
    if(flag == 1){
        oDiv.innerHTML = successInfo + value;
    }else{
        oDiv.innerHTML = unSuccessInfo + value;
    }
}

function eChart(){
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    $.get('pieChartDataServlet',function(res){
        var myData =JSON.parse(res);
        if(myData.code == 1){
            // 指定图表的配置项和数据
            var data = [
                            {value: myData.pest, name:'农药检测'},
                            {value: myData.veter, name:'兽药检测'},
                            {value: myData.metal, name:'重金属检测'},
                            {value: myData.toxin, name:'生物毒素检测'},
                            {value: myData.addi, name:'添加剂检测'},
                            {value: myData.wrap, name:'包装材料检测'}
                        ]
            var option = {
                title : {
                    text: '食品配料安全检测分析管理',
                    subtext: '数据可视化统计图',
                    x:'center'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['农药检测','兽药检测','重金属检测','生物毒素检测','添加剂检测','包装材料检测']
                },
                series : [
                    {
                        name: '访问来源',
                        type: 'pie',
                        radius : '75%',
                        center: ['50%', '55%'],
                        data: data,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
             // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
    })
}
function setUser(){

    var username = localStorage.getItem("name");
    document.getElementById("admin").value = username;
    $("#submit").click(function(){
        var user = document.getElementById("admin").value;
        var oldPass = document.getElementById("password").value;
        var newPass = document.getElementById("pass_1").value;
        var reNewPass = document.getElementById("pass_2").value;
        if(oldPass == ''){
            message('密码不能为空！', 0);
            return false;
        }else if(newPass == ''){
            message('新密码不能为空！', 0);
            return false;
        }else if(reNewPass == ''){
            message('确认密码不能为空！', 0);
            return false;
        }

        if(newPass != reNewPass){
            message('修改密码不一致！', 0);
            return false;
        }
        var sendData = {
            username: user,
            password: newPass,
            oldPassword: oldPass
        }
        $.post('UserChangePasswordServlet', sendData, function(res){
            var data = JSON.parse(res);
            if(data.code == "1"){
                message('修改密码成功！', 1);
                setInterval(function(){
                	window.location.href='login.html';
                },2000);
                
            }else{
                message('修改密码失败！', 1);
            }
        });
    });
}

function btnInit(){
	document.getElementById("foodId").value = '';
    document.getElementById("name").value = '';
    document.getElementById("date").value = '';
    document.getElementById("foodPest").value = '合格';
    document.getElementById("foodPestInfo").value = '';
    document.getElementById("foodVeter").value = '合格';
    document.getElementById("foodVeterInfo").value = '';
    document.getElementById("foodMetal").value = '合格';
    document.getElementById("foodMetalInfo").value = '';
    document.getElementById("foodToxin").value = '合格';
    document.getElementById("foodToxinInfo").value = '';
    document.getElementById("foodAddi").value = '合格';
    document.getElementById("foodAddiInfo").value = '';
    document.getElementById("foodWrap").value = '合格';
    document.getElementById("foodWrapInfo").value = '';
}
